<?php
/**
 * 栏目
 */
include LIB_PATH . '/YAction.class.php';
class CategoryAction extends YAction {
	public function __construct() {
		parent::__construct();
		
		// 登录检测
		if(!$this->isLogin()) {
			echo '_error Access Timeout'; exit;
		}
	}
	
	public function index() {
		// 列表
		$data = D('Category')->getListByPage();
		$pageString = $data['pageString'];
		unset($data['pageString']);
		$this->assign('data', $data);
		$this->assign('pageString', $pageString);
		
		$this->display();
	}
	
	// 添加
	public function addCategory() {
		$cat = D('Category')->getByCondition('1=1');
		$this->assign('cat', $cat);
		
		$this->display();
	}
	public function doAddCategory() {
		$data = array();
		
		$data['catname'] = y_getParam('catname');
		$data['parentid'] = y_getParam('parentid');
		$data['caturl'] = y_getParam('caturl');
		$data['isshow'] = y_getParam('isshow');
		$data['linktype'] = y_getParam('linktype');
		
		D('Category')->addOne($data);
		
		$this->success('添加成功');
	}
	
	// 修改
	public function editCategory() {
		$id = y_getParam('id', 'get');
		if(!is_numeric($id)) {exit;}
		
		$c = D('Category');
		$cat = $c->getByCondition('1=1');
		$this->assign('cat', $cat);
		
		$data = $c->getOneByPk($id);
		$this->assign('data', $data);
		
		$this->display();
	}
	public function doEditCategory() {
		$data = array();
		$id = y_getParam('pkid');
		if(!is_numeric($id)) {exit;}
		
		$data['catname'] = y_getParam('catname');
		$data['parentid'] = y_getParam('parentid');
		$data['caturl'] = y_getParam('caturl');
		$data['isshow'] = y_getParam('isshow');
		$data['linktype'] = y_getParam('linktype');
		
		D('Category')->updateOne('id='.$id, $data);
		
		$this->success('修改成功');
	}
	
	// 删除
	public function delCategory() {
		$id = y_getParam('id', 'get');
		if(!is_numeric($id)) {exit;}
		
		D('Category')->deleteOne('id='.$id);
		
		$this->success('删除成功');
	}
}